import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
//登陆
const login = () => import('../views/home/home.vue');
//首页
const index = () => import('../views/index/index.vue');
// 仙居广电幼儿园缴费记录
const record = () => import('../views/index/record.vue');
//活动
// const activity = () => import('../views/activity/activity.vue');
// //榜单
// const devote = () => import('../views/devote/devote.vue');
// //个人中心
// const center = () => import('../views/center/center.vue');
// //投稿
// const addgo = () => import('../views/addgo/addgo.vue');


const routes = [
    {
        path: '',
        redirect: '/home'
    },
    {
        path: '/home',
        component: login,
        name: "home",
        meta: { title: '仙居广电幼儿园缴费', bgColor: '#fff', isShare: true, }
    },
    {
        path: '/index',
        component: index,
        name: "index",
        meta: { title: '仙居广电幼儿园缴费', bgColor: '#f5f5f5', isShare: true, }
    },
    {
        path: '/record',
        component: record,
        name: "record",
        meta: { title: '仙居广电幼儿园缴费', bgColor: '#f5f5f5', isShare: true, }
    },

    // {
    //     path: '/activity',
    //     component: activity,
    //     name: "activity",
    //     meta: { title: '活动列表页', tabshow: true, isShare: true, }
    // },
    // {
    //     path: '/addgo',
    //     component: addgo,
    //     name: "addgo",
    //     meta: { title: '小记者', tabshow: true, bgColor: '#fff', isShare: true, }
    // },
    // {
    //     path: '/devote',
    //     component: devote,
    //     name: "devote",
    //     meta: { title: '贡献榜单', tabshow: true, bgColor: '#fff', isShare: true, }
    // },
    // {
    //     path: '/center',
    //     component: center,
    //     name: "center",
    //     meta: { title: '个人中心', tabshow: true, bgColor: '#fff', isShare: true, }
    // },
]
const router = new VueRouter({
    routes,
    base: process.env.NODE_ENV === "development" ? "" : "classBm-h5",
    mode: 'history',
});
// xjz/
router.beforeEach((to, form, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    document.querySelector("body").setAttribute("style", to.meta.bgColor ? "background-color:" + to.meta.bgColor + "" : "background-color:#f5f5f5");
    window.scrollTo(0, 0);
    // next();
    if (to.meta.isShare) {
        if (!to.query.gaze_control) {
            next({
                path: to.path,
                query: {
                    ...to.query,
                    gaze_control: '001',
                }
            })
        }
        else {
            next()
        }
    }
    else {
        next();
    }
});



// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}


// replace
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

export default router
